package com.wenhai.concurrency.thread;

/**
 * @ClassName InheritableThreadLocalDemo
 * @Description
 * @Author 谢文海
 * @Date 2021/4/9 1:34
 * @Version 1.0
 **/
public class InheritableThreadLocalDemo {
    public static ThreadLocal<String> threadLocal = new InheritableThreadLocal<>();
    public static void main(String[] args) throws InterruptedException {
        threadLocal.set("Hello, world");
        Thread subthread = new Thread(() -> {
            System.out.println("subThread ThreadLocal get() = " + threadLocal.get());
            threadLocal.set("sub");
            System.out.println("subThread ThreadLocal get() = " + threadLocal.get());
        }
        );
        subthread.start();
        System.out.println("main ThreadLocal get() = " + threadLocal.get());
        subthread.join();
        System.out.println("main ThreadLocal get() = " + threadLocal.get());
    }
}
